package model

import "context"

// Auth represents auth model
type Auth struct {
	PlayerID int
	err      error
}

// AddError add error to Auth
func (a *Auth) AddError(err error) {
	a.err = err
}

// GetError get error from auth
func (a *Auth) GetError() error {
	return a.err
}

// MakeAuth makes auth object
func MakeAuth() Auth {
	return Auth{}
}

// A private key for context that only this instance can access. This is important
// to prevent collisions between different context uses
var authIDCtxKey = &contextKey{"auth"}

// ForAuthContext get context contains auth info
func ForAuthContext(ctx context.Context) *Auth {
	raw := ctx.Value(authIDCtxKey)
	if raw == nil {
		return nil
	}
	auth := raw.(Auth)
	return &auth
}

// WithAuthContext set context contains auth info
func WithAuthContext(ctx context.Context, auth Auth) context.Context {
	ctxn := context.WithValue(ctx, authIDCtxKey, auth)
	return ctxn
}
